<template>
  <Row class="header" type="flex" align="middle" justify="space-between">
    <Col><router-link tag="a" to="/">零食小铺</router-link></Col>
    <div>
      <div v-if="isLogin">
        <router-link to="/profile"
          >欢迎 {{ username }}！<Icon type="md-contact" />个人中心  </router-link
        >
        <router-link to="/myorder"><Icon type="ios-document" />我的订单 </router-link>
        <a href="#" @click="logout"><Icon type="ios-exit" />退出登录</a>
      </div>
      <div v-else>
        <router-link tag="a" to="/login">登录 /</router-link>
        <router-link tag="a" to="/register">注册</router-link>
      </div>
    </div>
  </Row>
</template>

<script>
import { mapState } from "vuex";
export default {
  computed: {
    ...mapState(["username", "isLogin"])
  },
  methods: {
    logout() {
      localStorage.clear();
      this.$store.commit("clearLogin");
      this.$router.push("/");
    }
  }
};
</script>

<style lang="scss" scoped>
.header {
  height: 28px;
  background: #fff;
  padding: 0 20px;
  color: #933;
  a {
    color: #933;
  }
}
</style>
